package cn.xxm.dongbao.user.test;

import java.util.*;

/**
 * @program: ff-user
 * @link: 55864455@qq.com
 * @author: Mr.Xxm
 * @create: 2021-10-17 18:13
 **/
public class User {
    private static Map<String, String> userNamePwdList = new HashMap<>();

    static {
        userNamePwdList.put("110", "666666");
        userNamePwdList.put("xxm", "666666");
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            // 接受用户的输入的账号
            System.out.println("请输入账号");
            String inputName = sc.nextLine();
            if (inputName == null || "".equals(inputName)) {
                System.out.println("用户名不能为空");
                continue;
            }

            // 判断用户名是否存在
            boolean flag = checkUsernameIsExist(inputName);

            if (flag) {
                // 账号存在 整个流程从头开始
                System.out.println("不好意思,"+inputName +"已经被注册了");
                continue;
            }

            // 接受用户输入的密码
            System.out.println("请输入密码");
            String inputPwd = sc.nextLine();
            // 判断用户输入的密码是否为空,长度不低于6位等等
            boolean pwdFlag = checkPwd(inputPwd);
            if (pwdFlag) {
                // 密码符合规范
                // 插入数据库操作
                System.out.println("恭喜您注册成功");
                insertUsernameAndPwd(inputName, inputPwd);
                break;
            }else {
                System.out.println("不好意思,密码必须长度大于6");
            }
        }
    }

    private static void insertUsernameAndPwd(String inputName, String inputPwd) {
        userNamePwdList.put(inputName, inputPwd);
    }

    private static boolean checkPwd(String inputPwd) {
        return inputPwd != null && inputPwd.length() >= 6;
    }


    private static boolean checkUsernameIsExist(String inputName) {
        return userNamePwdList.keySet().contains(inputName);
    }
}
